/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package my12306.http;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import my12306.table.KeyValueItem;

/**
 * *
 * @author Jack
 */
//<editor-fold defaultstate="collapsed" desc=" TrainInfo ">  
public class TrainInfo {

    private TrainInfoMeta meta;
    private String startDate;
    /**
     * 序号
     */
    private String seq;
    /**
     * 65000D702104
     */
    private String trainNo;
    /**
     * D7021
     */
    private String trainCode;
    /**
     * 发站
     */
    private String fromStation;
    private String fromStationImage;
    /**
     * 到站
     */
    private String toStation;
    private String toStationImage;
    /**
     * 历时
     */
    private String period;
    /**
     * 发车时间
     */
    private String setoutTime;
    /**
     * 到站时间
     */
    private String arriveTime;
    /**
     * 商务座 -- 无此席别 未到起售时间 无 票已售完 有 票源充足
     */
    private String buzSeat;
    /**
     * 特等座
     */
    private String specialSeat;
    /**
     * 一等座
     */
    private String firstClassSeat;
    /**
     * 二等座
     */
    private String secondClassSeat;
    /**
     * 高级软卧
     */
    private String advSoftSleeperSeat;
    /**
     * 软卧
     */
    private String softSleeperSeat;
    /**
     * 硬卧
     */
    private String normalSleeperSeat;
    /**
     * 软座
     */
    private String softSeat;
    /**
     * 硬座
     */
    private String normalSeat;
    /**
     * 无座
     */
    private String standSeat;
    /**
     * 其它
     */
    private String otherSeat;
    private String otherInfo;
    private String buttonInfo;
    /**
     * 席别余票量的序号
     */
    public final static int BUZSEAT = 6;
    public final static int SPECIALSEAT = 7;
    public final static int FIRSTCLASSSEAT = 8;
    public final static int SECONDCLASSSEAT = 9;
    public final static int ADVSOFTSLEEPERSEAT = 10;
    public final static int SOFTSLEEPERSEAT = 11;
    public final static int NORMALSLEEPERSEAT = 12;
    public final static int SOFTSEAT = 13;
    public final static int NORMALSEAT = 14;
    public final static int STANDSEAT = 15;
    public final static int HAVEMANY = 999;
    public final static int HAVENONE = 0;
    public final static int HAVENOSUCHSEAT = -1;
    public final static int TIMENOTREACHED = -2;

    public TrainInfo() {
    }

    public String[] toArray() {
        return new String[]{
                    //seq,
                    trainCode, fromStation, toStation, period, setoutTime,
                    arriveTime, buzSeat, specialSeat, firstClassSeat, secondClassSeat, advSoftSleeperSeat,
                    softSleeperSeat, normalSleeperSeat, softSeat, normalSeat, standSeat, //otherSeat
                };

    }

    public List<Object> toList() {
        List<Object> result = new ArrayList<Object>();
        result.add(trainCode);  //0
//        result.add(fromStation);    //1
        result.add(new KeyValueItem(fromStation, fromStationImage));    //1
//        result.add(toStation);  //2
        result.add(new KeyValueItem(toStation, toStationImage));  //2
        result.add(period); //3
        result.add(setoutTime); //4
        result.add(arriveTime); //5
        result.add(buzSeat);    //6
        result.add(specialSeat);    //7
        result.add(firstClassSeat); //8
        result.add(secondClassSeat);    //9
        result.add(advSoftSleeperSeat); //10
        result.add(softSleeperSeat);    //11
        result.add(normalSleeperSeat);  //12
        result.add(softSeat);   //13
        result.add(normalSeat); //14
        result.add(standSeat);  //15
        result.add(buttonInfo);  //16
        return result;
    }

    /**
     * <option value="9">商务座</option> <option value="P">特等座</option> <option
     * value="M">一等座</option> <option value="O">二等座</option> <option
     * value="6">高级软卧</option> <option value="4">软卧</option> <option
     * value="3">硬卧</option> <option value="2">软座</option> <option
     * value="1">硬座</option> <option value="-1">无座</option>
     *
     * @param seatType
     * @return
     */
    private int getIndexBySeatType(String seatType) {
        int result = 0;
        if (seatType.equals("9")) {
            result = BUZSEAT;
        } else if (seatType.equals("P")) {
            result = SPECIALSEAT;
        } else if (seatType.equals("M")) {
            result = FIRSTCLASSSEAT;
        } else if (seatType.equals("O")) {
            result = SECONDCLASSSEAT;
        } else if (seatType.equals("6")) {
            result = ADVSOFTSLEEPERSEAT;
        } else if (seatType.equals("4")) {
            result = SOFTSLEEPERSEAT;
        } else if (seatType.equals("3")) {
            result = NORMALSLEEPERSEAT;
        } else if (seatType.equals("2")) {
            result = SOFTSEAT;
        } else if (seatType.equals("1")) {
            result = NORMALSEAT;
        } else if (seatType.equals("-1")) {
            result = STANDSEAT;
        }

        return result;
    }

    public int checkLeft(String seatType) {
        int result = -1;
        int index = getIndexBySeatType(seatType);
        String leftTicket = toList().get(index).toString();
        System.out.printf("\r\n席别：%s;序号：%d; 余票: %s \r\n", seatType, index, leftTicket);
        /*
         * -- 无此席别 * 未到起售时间 无 票已售完 有 票源充足
         */
        if (leftTicket.equals("无")) {
            result = HAVENONE;
        } else if (leftTicket.equals("有")) {
            result = HAVEMANY;
        } else if (leftTicket.equals("--")) {
            result = HAVENOSUCHSEAT;
        } else if (leftTicket.equals("*")) {
            result = TIMENOTREACHED;
        } else {
            try {
                result = Integer.parseInt(leftTicket);
            } catch (Exception ex) {
            }
        }

        return result;
    }

    /**
     * @return the seq
     */
    public String getSeq() {
        return seq;
    }

    /**
     * @param seq the seq to set
     */
    public void setSeq(String seq) {
        this.seq = seq;
    }

    /**
     * @return the trainNo like 6c0000G54802 etc.
     */
    public String getTrainNo() {
        return trainNo;
    }

    /**
     * @param trainNo the trainNo to set
     */
    public void setTrainNo(String trainNo) {
        this.trainNo = trainNo;
    }

    /**
     * @return the startStation
     */
    public String getFromStation() {
        return fromStation;
    }

    /**
     * @param startStation the startStation to set
     */
    public void setFromStation(String startStation) {
        this.fromStation = startStation;
    }

    /**
     * @return the distStation
     */
    public String getToStation() {
        return toStation;
    }

    /**
     * @param distStation the distStation to set
     */
    public void setToStation(String distStation) {
        this.toStation = distStation;
    }

    /**
     * @return the period
     */
    public String getPeriod() {
        return period;
    }

    /**
     * @param period the period to set
     */
    public void setPeriod(String period) {
        this.period = period;
    }

    /**
     * @return the setoutTime
     */
    public String getSetoutTime() {
        return setoutTime;
    }

    /**
     * @param setoutTime the setoutTime to set
     */
    public void setSetoutTime(String setoutTime) {
        this.setoutTime = setoutTime;
    }

    /**
     * @return the arriveTime
     */
    public String getArriveTime() {
        return arriveTime;
    }

    /**
     * @param arriveTime the arriveTime to set
     */
    public void setArriveTime(String arriveTime) {
        this.arriveTime = arriveTime;
    }

    /**
     * @return the buzSeat
     */
    public String getBuzSeat() {
        return buzSeat;
    }

    /**
     * @param buzSeat the buzSeat to set
     */
    public void setBuzSeat(String buzSeat) {
        this.buzSeat = buzSeat;
    }

    /**
     * @return the specialSeat
     */
    public String getSpecialSeat() {
        return specialSeat;
    }

    /**
     * @param specialSeat the specialSeat to set
     */
    public void setSpecialSeat(String specialSeat) {
        this.specialSeat = specialSeat;
    }

    /**
     * @return the firstClassSeat
     */
    public String getFirstClassSeat() {
        return firstClassSeat;
    }

    /**
     * @param firstClassSeat the firstClassSeat to set
     */
    public void setFirstClassSeat(String firstClassSeat) {
        this.firstClassSeat = firstClassSeat;
    }

    /**
     * @return the sceondClassSeat
     */
    public String getSecondClassSeat() {
        return secondClassSeat;
    }

    /**
     * @param sceondClassSeat the sceondClassSeat to set
     */
    public void setSecondClassSeat(String sceondClassSeat) {
        this.secondClassSeat = sceondClassSeat;
    }

    /**
     * @return the advSoftSleeperSeat
     */
    public String getAdvSoftSleeperSeat() {
        return advSoftSleeperSeat;
    }

    /**
     * @param advSoftSleeperSeat the advSoftSleeperSeat to set
     */
    public void setAdvSoftSleeperSeat(String advSoftSleeperSeat) {
        this.advSoftSleeperSeat = advSoftSleeperSeat;
    }

    /**
     * @return the softSleeperSeat
     */
    public String getSoftSleeperSeat() {
        return softSleeperSeat;
    }

    /**
     * @param softSleeperSeat the softSleeperSeat to set
     */
    public void setSoftSleeperSeat(String softSleeperSeat) {
        this.softSleeperSeat = softSleeperSeat;
    }

    /**
     * @return the normalSleeperSeat
     */
    public String getNormalSleeperSeat() {
        return normalSleeperSeat;
    }

    /**
     * @param normalSleeperSeat the normalSleeperSeat to set
     */
    public void setNormalSleeperSeat(String normalSleeperSeat) {
        this.normalSleeperSeat = normalSleeperSeat;
    }

    /**
     * @return the softSeat
     */
    public String getSoftSeat() {
        return softSeat;
    }

    /**
     * @param softSeat the softSeat to set
     */
    public void setSoftSeat(String softSeat) {
        this.softSeat = softSeat;
    }

    /**
     * @return the normalSeat
     */
    public String getNormalSeat() {
        return normalSeat;
    }

    /**
     * @param normalSeat the normalSeat to set
     */
    public void setNormalSeat(String normalSeat) {
        this.normalSeat = normalSeat;
    }

    /**
     * @return the standSeat
     */
    public String getStandSeat() {
        return standSeat;
    }

    /**
     * @param standSeat the standSeat to set
     */
    public void setStandSeat(String standSeat) {
        this.standSeat = standSeat;
    }

    /**
     * @return the otherSeat
     */
    public String getOtherSeat() {
        return otherSeat;
    }

    /**
     * @param otherSeat the otherSeat to set
     */
    public void setOtherSeat(String otherSeat) {
        this.otherSeat = otherSeat;
    }

    /**
     * @return the otherInfo
     */
    public String getOtherInfo() {
        return otherInfo;
    }

    /**
     * @param otherInfo the otherInfo to set
     */
    public void setOtherInfo(String otherInfo) {
        this.otherInfo = otherInfo;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("[").append(seq).append("]");
        sb.append("[").append(trainCode).append("]");
        sb.append("[").append(fromStation).append("]");
        sb.append("[").append(setoutTime).append("]");
        sb.append("[").append(toStation).append("]");
        sb.append("[").append(arriveTime).append("]");
        sb.append("[").append(period).append("]");
        sb.append("[").append(buzSeat).append("]");
        sb.append("[").append(specialSeat).append("]");
        sb.append("[").append(firstClassSeat).append("]");
        sb.append("[").append(secondClassSeat).append("]");
        sb.append("[").append(advSoftSleeperSeat).append("]");
        sb.append("[").append(softSleeperSeat).append("]");
        sb.append("[").append(normalSleeperSeat).append("]");
        sb.append("[").append(softSeat).append("]");
        sb.append("[").append(normalSeat).append("]");
        sb.append("[").append(standSeat).append("]");
        sb.append("[").append(otherSeat).append("]");
        sb.append("[").append(otherInfo).append("]");
        return sb.toString();
    }

    //</editor-fold>  
    /**
     * @return the meta
     */
    public TrainInfoMeta getMeta() {
        return meta;
    }

    /**
     * @param meta the meta to set
     */
    public void setMeta(TrainInfoMeta meta) {
        this.meta = meta;
    }

    public void setMeta(String meta) {
        this.meta = new TrainInfoMeta(meta);
    }

    /**
     * @return the startDate
     */
    public String getStartDate() {
        return startDate;
    }

    /**
     * @param startDate the startDate to set
     */
    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    /**
     * @return the trainCode like T256 etc
     */
    public String getTrainCode() {
        return trainCode;
    }

    /**
     * @param trainCode the trainCode to set
     */
    public void setTrainCode(String trainCode) {
        this.trainCode = trainCode;
    }

    /**
     * @return the buttonInfo
     */
    public String getButtonInfo() {
        return buttonInfo;
    }

    /**
     * @param buttonInfo the buttonInfo to set
     */
    public void setButtonInfo(String buttonInfo) {
        this.buttonInfo = buttonInfo;
    }

    /**
     * @return the fromStationImage
     */
    public String getFromStationImage() {
        return fromStationImage;
    }

    /**
     * @param fromStationImage the fromStationImage to set
     */
    public void setFromStationImage(String fromStationImage) {
        this.fromStationImage = fromStationImage;
    }

    /**
     * @return the toStationImage
     */
    public String getToStationImage() {
        return toStationImage;
    }

    /**
     * @param toStationImage the toStationImage to set
     */
    public void setToStationImage(String toStationImage) {
        this.toStationImage = toStationImage;
    }
}
